﻿using System;
using eCommerce.SagePay.Classes;

namespace eCommerce.SagePay.TestSite
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            // Basket Details
            BasketDetails basketDetails = new BasketDetails();
            basketDetails.Amount = 23.00m;
            basketDetails.CardHolder = "Mr CardHolder";
            basketDetails.CardNumber = "1234567891012";
            basketDetails.CardType = "VISA";
            basketDetails.Currency = "GBP";
            basketDetails.Description = "PRODUCT DESCRIPTION";
            basketDetails.ExpiryDate = "1012";
            basketDetails.StartDate = "1009";

            // Billing Details
            Billing billing = new Billing();
            billing.Address1 = "12 TESTY STREET";
            billing.Address2 = "";
            billing.City = "LONDON";
            billing.Country = "GB";
            billing.FirstNames = "BOBBY";
            billing.Phone = "123";
            billing.PostCode = "SW20 8SA";
            billing.State = "";
            billing.Surname = "TEST";

            // Delivery Details
            Delivery delivery = new Delivery();
            delivery.Address1 = "12 TESTY STREET";
            delivery.Address2 = "";
            delivery.Basket = "";
            delivery.City = "LONDON";
            delivery.Country = "GB";
            delivery.Email = "test@test.com";
            delivery.FirstNames = "BOBBY";
            delivery.IpAddress = "10.200.7.136";
            delivery.Phone = "123";
            delivery.PostCode = "SW20 8SA";
            delivery.State = "";
            delivery.Surname = "TEST";

            HttpRequestHelper helper = new HttpRequestHelper();
            SagePayResponse response = helper.SendRequest(basketDetails, billing, delivery);

            if (response.Status == "3DAUTH")
            {
                //strMD = findField("MD", strResponse)
                //strACSURL = findField("ACSURL", strResponse)
                //strPAReq = findField("PAReq", strResponse)
                //strPageState = "3DRedirect"
                Session["MD"] = response.MD;
                Session["PAReq"] = response.PAReq;
                Session["ACSURL"] = response.ACSUrl;
                Session["VendorTxCode"] = response.VendorTxCode;


                Response.Redirect("~/3DRedirect.aspx");
            }
        }
    }
}
